package com.ydd.controller.user;

import com.ydd.dto.FrontRegDTO;
import com.ydd.dto.LoginDTO;
import com.ydd.result.Result;
import com.ydd.service.IndexService;
import com.ydd.service.UserService;
import com.ydd.vo.JWtToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "home相关接口")
@RequestMapping("/home")
@Slf4j
@CrossOrigin
public class HomeController {
    @Autowired
    UserService userService;

    /**
     * 登录接口
     *
     * @param
     * @return
     */
    @PostMapping("/index/login")
    @ApiOperation("登录接口")
    public Result<JWtToken> login(@RequestBody FrontRegDTO loginDTO) {
        log.info("用户登录:{}", loginDTO.getMobile());
        JWtToken token = userService.login(loginDTO);

        Result<JWtToken> success = Result.success(token);
        success.setErrmsg("登录成功");
        return success;
    }

}
